package com.jt.safe.ui.activity

import android.graphics.Bitmap
import android.os.Environment
import com.cjt2325.cameralibrary.JCameraView
import com.cjt2325.cameralibrary.listener.ClickListener
import com.cjt2325.cameralibrary.listener.ErrorListener
import com.cjt2325.cameralibrary.listener.JCameraListener
import com.cjt2325.cameralibrary.util.FileUtil
import com.jt.safe.R
import com.jt.safe.base.BaseActivity
import com.jt.safe.viewmodel.NullViewModel
import kotlinx.android.synthetic.main.activity_camera.*
import java.io.File

class CameraActivity : BaseActivity<NullViewModel>() {
    override val layoutId: Int
        get() = R.layout.activity_camera

    override fun initView() {
        jCameraView.setSaveVideoPath(Environment.getExternalStorageDirectory().getPath() + File.separator + "saveJCamera")
        jCameraView.setFeatures(JCameraView.BUTTON_STATE_ONLY_RECORDER)
        jCameraView.setTip("长按拍摄视频")
        jCameraView.setMediaQuality(JCameraView.MEDIA_QUALITY_HIGH)
        jCameraView.setErrorLisenter(object : ErrorListener {
            override fun onError() {

            }

            override fun AudioPermissionError() {

            }
        })

        //JCameraView监听
        jCameraView.setJCameraLisenter(object : JCameraListener {
            override fun captureSuccess(bitmap: Bitmap) {
                //获取图片bitmap
                val path =
                    FileUtil.saveBitmap("saveJCamera", bitmap, "${System.currentTimeMillis()}.png")

            }

            override fun recordSuccess(url: String, firstFrame: Bitmap) {
                //获取视频路径
                val path =
                    FileUtil.saveBitmap("saveJCamera", firstFrame, "${System.currentTimeMillis()}.png")
                val imageFile = File(path)
                val file = File(url)

            }
        });

        jCameraView.setLeftClickListener(object : ClickListener {
            override fun onClick() {
                this@CameraActivity.finish();
            }
        });
        jCameraView.setRightClickListener(object : ClickListener {
            override fun onClick() {

            }
        })
    }

    override fun createObserver() {

    }
}